package spe.ui.editor.policy;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.BendpointEditPolicy;
import org.eclipse.gef.requests.BendpointRequest;

import spe.model.notation.Link;
import spe.ui.editor.command.AbstractBendpointCommand;
import spe.ui.editor.command.BendpointCreatingCommand;
import spe.ui.editor.command.BendpointDeletingCommand;
import spe.ui.editor.command.BendpointMovingCommand;

public class LinkBendpointEditPolicy extends BendpointEditPolicy
{

	@Override
	protected Command getCreateBendpointCommand(final BendpointRequest request)
	{
		//System.out.println(String.format("[LinkBendpointEditPolicy] CreateBendpointCommand %s", request));
		BendpointCreatingCommand cmd = new BendpointCreatingCommand();
		cmd.setLink((Link)request.getSource().getModel());
		cmd.setLocation(request.getLocation());
		cmd.setIndex(request.getIndex());
		return cmd;
	}

	@Override
	protected Command getDeleteBendpointCommand(final BendpointRequest request)
	{
		BendpointDeletingCommand cmd = new BendpointDeletingCommand();
		cmd.setLink((Link)request.getSource().getModel());
		cmd.setLocation(request.getLocation());
		cmd.setIndex(request.getIndex());
		return cmd;
	}

	@Override
	protected Command getMoveBendpointCommand(final BendpointRequest request)
	{
		//System.out.println(String.format("[LinkBendpointEditPolicy] MoveBendpointCommand %s", request));
		BendpointMovingCommand cmd = new BendpointMovingCommand();
		cmd.setLink((Link)request.getSource().getModel());
		cmd.setLocation(request.getLocation());
		cmd.setIndex(request.getIndex());
		return cmd;
	}
	
	private void fillCommand(BendpointRequest request, AbstractBendpointCommand command) 
	{
		
		Point ref1 = getConnection().getSourceAnchor().getReferencePoint();
		Point ref2 = getConnection().getTargetAnchor().getReferencePoint();
		//command.setRelativeDimensions(p.getDifference(ref1), p.getDifference(ref2));
		command.setLink((Link)request.getSource().getModel());
		command.setIndex(request.getIndex());
	}

}
